<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/static/component/pear/css/pear.css" />
    <script src="/static/component/layui/layui.js"></script>
    <script src="/static/component/pear/pear.js"></script>
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-row" style="margin-bottom: 15px;">
                <div class="layui-col-xs6">
                    <label class="layui-form-label">
                        名称
                    </label>
                    <div class="layui-col-sm8">
                        <input type="text" class="layui-input layui-form-danger" placeholder="名称" name="name" type="text" value="{$model['name']??""}"/>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <label class="layui-form-label">
                        编号
                    </label>
                    <div class="layui-col-sm2">
                        <input type="text" class="layui-input layui-form-danger" placeholder="编号" name="bianhao" type="text" value="{$model['bianhao']??""}"/>
                    </div>
                </div>
            </div>
            <div class="layui-row" style="margin-bottom: 15px;">
                <div class="layui-col-xs3">
                    <label class="layui-form-label">
                        电话
                    </label>
                    <div class="layui-col-sm6">
                        <input type="text" class="layui-input layui-form-danger" placeholder="电话" name="tel" type="text" value="{$model['tel']??""}"/>
                    </div>
                </div>
                <div class="layui-col-xs3">
                    <label class="layui-form-label">
                        作者
                    </label>
                    <div class="layui-col-sm6">
                        <input type="text" class="layui-input layui-form-danger" placeholder="作者" name="zuozhe" type="text" value="{$model['zuozhe']??""}"/>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <label class="layui-form-label">
                        外链
                    </label>
                    <div class="layui-col-sm8">
                        <input type="text" class="layui-input layui-form-danger" placeholder="外链" name="outurl" type="text" value="{$model['outurl']??""}"/>
                    </div>
                </div>
            </div>
            <div class="layui-row" style="margin-bottom: 15px;">
                <div class="layui-col-xs6">
                    <label class="layui-form-label">音频：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="mp3url"  id="inputmp3url" placeholder="音频地址" value="" class="layui-input"> 
                    </div>
                    <button class="pear-btn pear-btn-primary pear-btn-sm upload-mp3url" type="button" name="upload-mp3url">
                        上传音频
                    </button>
                </div>
                <div class="layui-col-xs6">
                    <label class="layui-form-label">视频：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="video"  id="inputvideourl" placeholder="视频地址" value="" class="layui-input"> 
                    </div>
                    <button class="pear-btn pear-btn-primary pear-btn-sm upload-video" type="button" name="upload-video">
                        上传视频
                    </button>
                </div>
            </div>
            <div class="layui-row" style="margin-bottom: 15px;" id="div1">
                <div class="layui-col-xs6">
                    <label class="layui-form-label">
                        组别
                    </label>
                    <div class="layui-input-block">
                        <select name="group" lay-verify="required">
                            <!-- <option value="1">1</option>
                            <option value="2">2</option> -->
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    简介
                </label>
                <div class="layui-input-block">
                    <textarea id="content" name="content" type="text/plain" style="width:100%;margin-bottom:20px;">{$model['content']??""}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    详情
                </label>
                <div class="layui-input-block">
                    <textarea id="xiangqing" name="xiangqing" type="text/plain" style="width:100%;margin-bottom:20px;">{$model['xiangqing']??""}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    照片
                </label>
                <div class="layui-input-block">
                    <!-- {:opt_photo("image")} -->
                <button class="pear-btn pear-btn-primary pear-btn-sm upload-image" type="button">
                    <i class="fa fa-image">
                    </i>
                    上传图片
                </button>
                <input name="image" type="hidden" value="{$model['image']??""}"/>
                <div class="upload-image">
                    <span>
                    </span>
                    <img class="upload-image" src="{$model['image']??""}"/>
                </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    审核状态
                </label>
                <div class="layui-input-block">
                    <input type="radio" name="shenhe" value="0" title="通过" checked>
                    <input type="radio" name="shenhe" value="1" title="待定">
                </div>
            </div>
            <input name="biaoid" type="hidden" value="{$biaoid}"/>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <!-- <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button> -->
        </div>
    </div>
</form>
<script>
    layui.use(['form', 'jquery','tinymce','uploads','upload'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let tinymce = layui.tinymce;

        var upload = layui.upload;
        var leftUrl = window.location.pathname.split("/")[1];
        if(leftUrl.indexOf(".php")>0){
            var leftUrl = '/'+ leftUrl;
        }else{
            var leftUrl = '';
        }
        upload.render({
            elem: "[name='upload-mp3url']",
            url: leftUrl + '/tpadmin/index/uploadyinpin',
            accept: 'audio',
            before: function(obj){
                layer.msg('上传中', {icon: 16, time: 0});
            },
            done: function (res) {
                layer.msg('上传成功');
                // console.log(res.data.src);
                $('#inputmp3url').val(res.data.src);
            }
        });

        upload.render({
            elem: "[name='upload-video']",
            url: leftUrl + '/tpadmin/index/uploadshipin',
            accept: 'video',
            before: function(obj){
                layer.msg('上传中', {icon: 16, time: 0});
            },
            done: function (res) {
                layer.msg('上传成功');
                // console.log(res.data.src);
                $('#inputvideourl').val(res.data.src);
            }
        });


        $.ajax({
            url:'{$Request.root}/admin.zccandidate/bianhaofenzu',
            data:{biaoid:{$biaoid}},
            dataType: 'json',
            type: 'POST',
            success: function(res) {
                // console.log(res);
                var bianhao = res.bianhao + 1;
                $("[name='bianhao']").val(bianhao);
                if(res.fenzu == 0){
                    $("#div1").css("display","none");
                }else{
                    var fenzuname = res.fenzuname.split('/');
                    var htmla = '';
                    for (var j = 0; j < fenzuname.length; j++) {
                        htmla += "<option value=" +fenzuname[j] + ">" +fenzuname[j] + "</option>";
                    }
                    $("[name='group']").append(htmla);
                    form.render();
                }
            }
        });

        


        
        //建立编辑器
        var content  = tinymce.render({ elem: "#content",height: 350,inline:false,placeholder:"在此输入正文",
        relative_urls: false,remove_script_host: false,
        auto_focus: true,toolbar_mode : "floating",toolbar_sticky: false,quickbars_insert_toolbar:"",images_upload_url:"{$Request.root}/index/upload",image_advtab: true,menubar:true});

        //建立编辑器
        var xiangqing  = tinymce.render({ elem: "#xiangqing",height: 350,inline:false,placeholder:"在此输入正文",
        relative_urls: false,remove_script_host: false,
        auto_focus: true,toolbar_mode : "floating",toolbar_sticky: false,quickbars_insert_toolbar:"",images_upload_url:"{$Request.root}/index/upload",image_advtab: true,menubar:true});
        
        form.on('submit(save)', function (data) {
            data.field.content=content.getContent();
            data.field.xiangqing=xiangqing.getContent();
            //编写自己的判断逻辑（不能为空、必须为数字等）
            $.ajax({
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (res) {
                    //判断有没有权限
                    if (res && res.code == 999) {
                        layer.msg(res.msg, {
                            icon: 5,
                            time: 2000,
                        })
                        return false;
                    } else if (res.code == 200) {
                        layer.msg(res.msg,{icon:1,time:1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("dataTable");
                        });
                    } else {
                        layer.msg(res.msg,{icon:2,time:1000});
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>